package com.kcht.test.rfid;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * 脚本执行
 */
@Slf4j
@Component
public class ScriptExecutor {
    @Value("${service.script-path:}")
    private String scriptPath;


    public void runScript() {
        if (this.scriptPath != null&&!"".equals(this.scriptPath)) {
            Runtime runtime = Runtime.getRuntime();
            try {
                log.info("触发脚本启动");
                runtime.exec("cmd /c start "+scriptPath);
                log.info("脚本启动成功");
            } catch (IOException e) {
                log.info("执行命令异常", e);
            }
        } else {
            log.info("未设置脚本,请执行手动重启");
        }
    }
}
